package ru.ncedu.java.vlku.hrs.uil.cmd;

import ru.ncedu.java.vlku.hrs.bll.HRSManager;
import ru.ncedu.java.vlku.hrs.bll.HRSManagerFactory;
import ru.ncedu.java.vlku.hrs.model.CustomerAccount;

import javax.management.BadAttributeValueExpException;

public class UpdateCustomerAccount implements Command {
    // update customer_account <id> <new_name> <new_email> <new_password> <new_phone>
    @Override
    public void execute( String[] args ) {
        if (args.length != 7)
            throw new IllegalArgumentException();
        CustomerAccount ca = new CustomerAccount(args[3], args[4], args[5], args[6]);
        ca.setId(Long.parseLong(args[2]));
        HRSManager manager = HRSManagerFactory.getInstance().getHRSManager();
        try {
            manager.updateCustomerAccount(ca);
        } catch ( BadAttributeValueExpException e ) {
            throw new IllegalArgumentException(e);
        }
    }
}
